import $service from '../../../../service.js';
var user_type;
var user_id;
var inquiryinfo={};
var page = 0;
var isMeasured;
var that;
Page({
    data:{
       "active" : true,
       measuredDataList:[],
       measuredDataMap:{},
       num:0,
       loadingText: '',
       loadingType: true
       
    },
    onLoad(e){//inquiryinfo里包含  inquiry_patient_id、 log_id
        inquiryinfo=$service.strToJson(e.inquiryinfo)
    },
    onShow(){
        that =this.data;
        if(!$service.isUndefinedAndEmpty($service.getUserLocalStorage().user_type)){
        		user_type = $service.getUserLocalStorage().user_type;
        	}
         if(user_type == 1){//1用户 1门店
             user_id = $service.getUserLocalStorage().user_id;
         }else{
             user_id = $service.getUserLocalStorage().store_id;
         }
         this.publicUtil_getPatientMeasuredDataList()
    },
    onPullDownRefresh() {
        page = 0;
        this.setData({
            loadingText: '加载更多'
        })
        this.publicUtil_getPatientMeasuredDataList();
        wx.stopPullDownRefresh()
    },
    onReachBottom: function() {
        if (that.loadingType == true) {
            page++
            this.publicUtil_getPatientMeasuredDataList();
        } else {
            this.setData({
                loadingText: '没有更多了'
            })
        }
    },
    loading(){
        if (that.loadingType == true) {
            page++
            this.publicUtil_getPatientMeasuredDataList(); 
        } else {
            this.setData({
                loadingText: '没有更多了'
            })
        }
    },
    //获取历史测量数据
    publicUtil_getPatientMeasuredDataList:function(){
        var jsonData ={
            "inquiry_patient_id" : inquiryinfo.inquiry_patient_id,
            "page" :page,
            "log_id" : inquiryinfo.log_id
        }
        console.log(jsonData)
        var jsonAjax = {
            "url": "publicUtil_getPatientMeasuredDataList.do",
            "jsonData": jsonData,
        }
        $service.getAjaxData(jsonAjax, this.publicUtil_getPatientMeasuredDataList_back);
    },
    publicUtil_getPatientMeasuredDataList_back:function(jsonBack){
        var data=$service.strToJson(jsonBack.data).data; 
        isMeasured = data.isMeasured
        if(!$service.isUndefinedAndEmpty(data.measuredDataMap.lrsj)){
            that.num = 1;
            data.measuredDataMap.lrsj = data.measuredDataMap.lrsj.substring(0, 10)
        }else{
            that.num = 0
        }
        
        if (page == 0) {
            that.loadingText = '';
            that.measuredDataList = data.measuredDataList;
        } else {
            if (data.measuredDataList.length <= 0) {
                that.loadingType = false;
                that.loadingText = '没有更多了';
            } else {
                for (var i = 0; i < data.measuredDataList.length; i++) {
                    that.measuredDataList.push(data.measuredDataList[i]);
                    that.loadingText = '加载更多';
                }
            }
        }
        
        for (var i = 0; i < that.measuredDataList.length; i++) {
            that.measuredDataList[i].lrsj = that.measuredDataList[i].lrsj.substring(0, 10)
        }
        this.setData({
            measuredDataMap : data.measuredDataMap,
            measuredDataList:that.measuredDataList,
            num:that.num,
            loadingText: that.loadingText,
            loadingType: that.loadingType
        })
    },
})